<%@page contentType="application/x-download" pageEncoding="UTF-8"
	import="com.mop.dinnerbook.dao.*,java.util.*,com.mop.dinnerbook.bean.*,java.io.*,java.text.*"%>
<%
        Manager manager = (Manager)session.getAttribute("manager");
        if(manager != null){
            DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            String _beginDate = request.getParameter("beginDate");
            String _endDate = request.getParameter("endDate");
            Date beginDate = null;
            Date endDate = null;
            if(_beginDate != null && !_beginDate.equals(""))
                beginDate = formatter.parse(_beginDate);
            if(_endDate !=null && !_endDate.equals(""))
                endDate = formatter.parse(_endDate);
            response.reset();
            ManageDAO dao = new ManageDAO();
            String fdir = application.getInitParameter("exportDir");
            System.out.println(fdir);
            fdir = application.getRealPath(fdir) + "/";
            System.out.println(fdir);
            String filename = dao.exportByDate(fdir,beginDate,endDate);
            String sfilename = fdir + filename;
            response.setContentType("application/x-download");
            response.setHeader("Content-Disposition", "attachment;filename="
                            + filename);
            FileInputStream sin = null;
            OutputStream os = response.getOutputStream();
            try {
                    sin = new FileInputStream(sfilename);
                    byte[] b = new byte[1024];
                    int n = 0;
                    while ((n = sin.read(b)) > 0) {
                            os.write(b, 0, n);
                    }
                    os.flush();
            } catch (Exception e) {
                    e.printStackTrace();
            } finally {
                    if (sin != null)
                            sin.close();
                    if (os != null)
                            os.close();
            }
            new File(sfilename).delete();
        }else{
            response.setContentType("text/plain");
            out.write("导出失败，权限不足！");
        }
%>